package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.User;
import cn.edu.lingnan.service.userservice;
import cn.edu.lingnan.service.userserviceimp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class UpdateServlet extends HttpServlet {
    userservice us=new userserviceimp();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        int id = Integer.parseInt(req.getParameter("id"));
        String name = req.getParameter("name");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        int age = Integer.parseInt(req.getParameter("age"));
        String gender = req.getParameter("gender");
        String major = req.getParameter("major");
        System.out.println("学院："+major);
        User user = new User( id, name, username, password, age, gender, major,"","","",0);
        System.out.println("更新用户信息："+ user);
        Integer i = us.updateUser(user);
        req.getServletContext().setAttribute("user", user);
        List<User> userList = us.selectall();

        req.getServletContext().setAttribute("userList", userList);
        resp.sendRedirect(req.getContextPath() + "/update.jsp?submitted=true");
    }
}
